#!/bin/awk -f
## This is derived from "zpuck"
## zpuck was written for Al13Co4, this is a generalization.
## USAGE: zshift OBJNAME=config:denom
## example:
## zshift hexagon=0321100:4 star=213:4
## means: tiling contains 7 hexagons and 3 stars, and we apply 
## shift 0/4 to the first, 3/4 to the second etc hexagon, shift 2/4 to the first
## star etc.
## NOTE: orbit within object must have "shift" string in the name!
BEGIN{
  for(i=1;i<ARGC;i++){
    n=split(ARGV[i],a,"=");
    if(n==2){
      x++;
      split(a[2],b,":");
      denom=b[2];
      if(x>1)fext=fext"_";
      fext=fext""a[1]"."b[1];
      nn=split(b[1],c,"");
#      print a[1],a[2],b[1],b[2],denom;
      for(j=1;j<=nn;j++)z[a[1]"_"j]=c[j]/denom;
    }else{
      fn=ARGV[i];
    }
  }
  ARGC=2; if(fn!=""){ARGV[1]=fn}else{ARGV[1]="-"};
  fo="xyz."fext;
#  print fo;
}
FNR<5{print $0>fo }
FNR>4{
  argu=$7;
  if(z[argu]!=""&&$6~/shift/){zz=$3+z[argu]}else{zz=$3};
  sh="-";
  if(z[argu]!=""){sh="shift+"z[argu]};
  printf("%13.8f %13.8f %10.6f %5i %3i %5s %s %s\n",$1,$2,bound(zz),$4,$5,$6,$7,sh)>fo;
}
END{}
function bound(y, z){z=y-int(y);if(z<-0.5){z+=1.0};if(z>=0.5){z+=-1.0};return z}
